import type { IColumnsOption } from 'vc';
import { INDEX, COMPANY_NAME, INFO_SOURCE, PROVINCE, CITY, INDUSTRY_CATEGORY, BUSINESS_DATA, REGISTERED_CAPITAL } from '@/utils';

export function useTable() {
  const tableData = ref([]);

  const columns = ref<IColumnsOption[]>([
    { ...INDEX },
    { ...COMPANY_NAME },
    {
      title: '披露日期',
      field: 'noticeDate',
      width: 100,
      align: 'center',
      sortable: true,
      sortBy: 'noticeDate'
    },
    { ...INFO_SOURCE('tagName') },
    {
      title: '认定级别',
      field: 'postLevel',
      width: 150,
      align: 'center',
      sortable: true,
      sortBy: 'postLevel',
      slots: {
        default: ({ row }) => {
          const map = {
            0: '其他',
            1: '行业级',
            2: '区县级',
            3: '市级',
            4: '省级',
            5: '国家级'
          };
          const title = map[row.postLevel] || row.postLevel;
          return <span title={title}>{title}</span>;
        }
      }
    },
    {
      title: '认定年度',
      field: 'tagYear',
      width: 100,
      align: 'center',
      sortable: true,
      sortBy: 'tagYear',
      formatter({ row, column }) {
        return row[column.field] ? row[column.field] + '年' : '-';
      }
    },
    {
      title: '认定单位',
      field: 'dataSource',
      width: 200,
      sortable: true,
      sortBy: 'dataSource'
    },
    { ...PROVINCE },
    { ...CITY },
    { ...INDUSTRY_CATEGORY },
    { ...BUSINESS_DATA },
    { ...REGISTERED_CAPITAL }
  ]);

  return {
    tableData,
    columns
  };
}
